package com.itzz.spring_zhoneHeng.base;



//统一响应数据
public class RestResponse<T> {
    private int code;  //数据状态码
    private String message;//消息类型
    private T data;//返回数据

    public RestResponse(int code, String message) {
        this.code = code;
        this.message = message;
    }

    public RestResponse(int code, String message, T data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    //返回无数据响应体 (修改添加删除)
    public static RestResponse ok(){

        return  new RestResponse(SystemCode.OK.getCode(), SystemCode.OK.getMessage());
    }

    //返回有数据响应体(查询)
    public static<D> RestResponse ok(D data){

        return  new RestResponse(
               SystemCode.OK.getCode(), SystemCode.OK.getMessage(),data
        );
    }

    //返回数据失败
    public static RestResponse fail(int code,String message){

        return new RestResponse(code, message);
    }



}
